home *** CD-ROM | disk | FTP | other *** search
- // Tools Plus Tutorial -- Buttons on two windows
-
-
-
- #include "ToolsPlus.h"
- #include "String.h" // ANSI C string manipulation
-
-
-
- #define ApplMenu 0 // Menu constants to make code more readable…
- #define FileMenu 1
- #define EditMenu 2
-
- #define VendorWindow 1 // Window constants (just to make the code readable)…
- #define DebuggerWindow 2
-
- #define OkButton 255 // Button constants…
- #define CancelButton 254
-
- #define checkSymFile 1
- #define checkFullPath 2
- #define checkLinkMap 3
- #define checkA6 4
- #define checkDebugger 5
-
- #define typeAle 1
- #define typeDraft 2
- #define typeLager 3
- #define typeLite 4
- #define typeWater 5
- #define levelHigh 10
- #define levelMedium 11
- #define levelLow 12
-
-
-
- TPPollRecord Poll; // Polling record to retrieve event information
- Boolean ExitTheDemo; // Should the demo terminate?
- short theButton; // Button counter
-
-
- void ApplicationInitialization (void);
- void ProcessMenuSelection (void);
- void DrawVendorWindow (void);
-
-
-
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void main(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- MaxApplZone();
-
-
- if (!InitToolsPlus(1, 2, UseColor))
- ExitToShell();
-
- ApplicationInitialization();
-
- while (!ExitTheDemo) // Main Event Loop
- {
- if (PollSystem(&Poll)) // If an event is available, process the event…
- {
- switch (Poll.What)
- {
- case doMenu:
- ProcessMenuSelection();
- break;
-
-
- case doChgWindow: // User clicked an inactive window…
- ActivateWindow(Poll.Window);
- break;
-
-
- case doRefresh: // Part of window needs to be refreshed
- BeginUpdate(WindowPointer(Poll.Window)); //Restrict drawing to area that needs it
- if (Poll.Window == VendorWindow)
- DrawVendorWindow();
- EndUpdate(WindowPointer(Poll.Window)); //End the update for the window (unrestricted drawing)
- break;
-
-
- case doGoAway: // User clicked a window's close box
- WindowClose(Poll.Window);
- break;
-
-
- case doButton: // User clicked a button…
- // Subsequent action takes place on this window (current grafPort)
- CurrentWindow(Poll.Window);
- if (Poll.Window == VendorWindow) // Button clicked in "Vendor" window…
- {
- switch (Poll.Button.Num)
- {
- case typeAle: case typeDraft: case typeLager: case typeLite: case typeWater:
- for (theButton = typeAle; theButton <= typeWater; theButton++)
- SelectButton(theButton, (Poll.Button.Num == theButton));
- break;
- case levelHigh: case levelMedium: case levelLow:
- for (theButton = levelHigh; theButton <= levelLow; theButton++)
- SelectButton(theButton, (Poll.Button.Num == theButton));
- break;
- case OkButton: case CancelButton:
- WindowClose(Poll.Window);
- break;
- }
- }
- else // Button clicked in the "Debugger" window…
- {
- switch (Poll.Button.Num)
- {
- case checkSymFile: case checkFullPath: case checkLinkMap:
- case checkA6: case checkDebugger:
- SelectButton(Poll.Button.Num, !ButtonIsSelected(Poll.Button.Num));
- if (Poll.Button.Num == checkSymFile)
- {
- // "Check full path" box is available only when
- // "Generate SYM File" box is on…
- EnableButton(checkFullPath, ButtonIsSelected(checkSymFile));
- if (!ButtonIsEnabled(checkFullPath))
- SelectButton(checkFullPath, false);
- }
- break;
-
- case OkButton: case CancelButton:
- WindowClose(Poll.Window);
- break;
- }
- }
- break;
-
-
- case doPictButton: case doKeyDown: case doAutoKey:
- case doClickField: case doScrollBar: case doListBox:
- case doPopUpMenu: case doClick:
- break; // Other core events we're ignoring in this app
-
-
- default: // All other events are ignored
- break;
- }
- }
- }
- }
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void ApplicationInitialization (void)
- {
- // Do all the application setup before you start polling for events…
-
- // Create an Apple menu with an 'About…' item…
- AppleMenu("\pAbout My App…");
-
- // Create the standard File and Edit menus…
- Menu(FileMenu, 0, enabled, "\pFile");
- Menu(FileMenu, 1, disabled, "\pNew/N");
- Menu(FileMenu, 2, disabled, "\pOpen/O");
- Menu(FileMenu, 3, disabled, "\pClose/W");
- Menu(FileMenu, 4, disabled, mDividingLine);
- Menu(FileMenu, 5, enabled, "\pQuit/Q");
-
- Menu(EditMenu, 0, enabled, "\pEdit");
- Menu(EditMenu, 1, disabled, "\pUndo/Z");
- Menu(EditMenu, 2, disabled, mDividingLine);
- Menu(EditMenu, 3, disabled, "\pCut/X");
- Menu(EditMenu, 4, disabled, "\pCopy/C");
- Menu(EditMenu, 5, disabled, "\pPaste/V");
- Menu(EditMenu, 6, disabled, "\pClear");
- Menu(EditMenu, 7, disabled, mDividingLine);
- Menu(EditMenu, 8, disabled, "\pShow Clipboard…");
- UpdateMenuBar();
-
-
- // Create the "Vendor" window and populate it…
- WindowOpen(VendorWindow, 0, 0, 250, 150, "\pVendor", noGrowDocProc + wTile, GoAway, NotModal);
- TextFont(geneva);
- TextSize(9);
- NewButton(typeAle, 25, 30, 60, 42, "\pAle", radioButProc + useWFont, enabled, selected);
- NewButton(typeDraft, 25, 45, 70, 57, "\pDraft", radioButProc + useWFont, enabled, notSelected);
- NewButton(typeLager, 25, 60, 70, 72, "\pLager", radioButProc + useWFont, enabled, notSelected);
- NewButton(typeLite, 25, 75, 62, 87, "\pLite", radioButProc + useWFont, enabled, notSelected);
- NewButton(typeWater, 25, 90, 70, 102, "\pWater", radioButProc + useWFont, enabled, notSelected);
-
- NewButton(levelHigh, 140, 29, 190, 43, "\pHigh", radioButProc, enabled, notSelected);
- NewButton(levelMedium, 140, 46, 214, 60, "\pMedium", radioButProc, enabled, selected);
- NewButton(levelLow, 140, 63, 188, 77, "\pLow", radioButProc, enabled, notSelected);
-
- NewButton(CancelButton, 110, 110, 167, 130, "\pCancel", pushButProc, enabled, notSelected);
- NewButton(OkButton, 185, 110, 235, 130, "\pOk", pushButProc + DefaultButton, enabled, notSelected);
- DrawVendorWindow;
-
-
- // Create the "Debugger" window and populate it…
- WindowOpen(DebuggerWindow, 0, 0, 250, 150, "\pDebugger", noGrowDocProc + wTile, GoAway, NotModal);
- NewButton(checkSymFile, 35, 10, 160, 26, "\pCreate SYM File", checkBoxProc, enabled, notSelected);
- NewButton(checkFullPath, 53, 26, 208, 42, "\pFull Path in SYM File", checkBoxProc, disabled, notSelected);
- NewButton(checkLinkMap, 35, 42, 180, 58, "\pGenerate Link Map", checkBoxProc, enabled, notSelected);
- NewButton(checkA6, 35, 58, 230, 74, "\pGenerate A6 Stack Frames", checkBoxProc, enabled, notSelected);
- NewButton(checkDebugger, 35, 74, 200, 90, "\pThe Debugger™ Aware", checkBoxProc, enabled, notSelected);
-
- NewButton(CancelButton, 110, 110, 167, 130, "\pCancel", pushButProc, enabled, notSelected);
- NewButton(OkButton, 185, 110, 235, 130, "\pOk", pushButProc + DefaultButton, enabled, notSelected);
-
-
- ExitTheDemo = false;
- }
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void DrawVendorWindow (void)
- {
- // Draw the contents of a window. It's good to have this code in a separate
- // routine because you need to use it [1] when a window is first opened, and
- // [2] when a window needs to be refreshed.
-
- Rect theRect;
- char theStr[255];
-
-
-
- // Subsequent drawing takes place on this window (current grafPort)
- CurrentWindow(VendorWindow);
- TextFont(systemFont);
- TextSize(12);
-
- // Draw the 'Type' group box…
- SetRect(&theRect, 15, 18, 85, 112);
- FrameRect(&theRect);
- SetRect(&theRect, 20, 10, 56, 26);
- strcpy(theStr, "Type");
- TextBox(theStr, strlen(theStr), &theRect, teJustCenter);
-
- // Draw the 'Level' group box…
- SetRect(&theRect, 130, 18, 220, 85);
- FrameRect(&theRect);
- SetRect(&theRect, 135, 10, 177, 26);
- strcpy(theStr, "Level");
- TextBox(theStr, strlen(theStr), &theRect, teJustCenter);
- }
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void ProcessMenuSelection (void)
- {
- #define NewItem 1
- #define OpenItem 2
- #define CloseItem 3
- #define QuitItem 5
-
- short theButton;
-
- switch (Poll.Menu.Num)
- {
- case ApplMenu: // Apple menu's 'About…' item
- theButton = AlertBox(NoIcon, "\pThis is my application’s about box. (Click to close)", NoButtonAlert);
- break;
-
- case FileMenu:
- switch (Poll.Menu.Item)
- {
- case NewItem:
- break;
- case OpenItem:
- break;
- case CloseItem:
- break;
- case QuitItem:
- ExitTheDemo = true;
- break;
- }
- }
-
- MenuHilite(0); // Turn off highlighted menu
- }